from django.db import models
from user.models import CustomUser
from main.models import Article

# Create your models here.

class Collect(models.Model):
    user = models.ForeignKey(verbose_name="用户",to=CustomUser, on_delete=models.CASCADE)
    article = models.ForeignKey(verbose_name="文章",to=Article, on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name="收藏时间",auto_now_add=True)

    def __str__(self):
        return f"{self.user} 收藏:{self.article}"
    class Meta:
         unique_together = ('user','article')


class Comment(models.Model):
    article = models.ForeignKey(verbose_name="文章",to=Article, on_delete=models.CASCADE)
    user = models.ForeignKey(verbose_name="点评人",to=CustomUser, on_delete=models.CASCADE)
    content = models.TextField(verbose_name="评论内容")
    created_at = models.DateTimeField(auto_now_add=True)
    parent = models.ForeignKey(verbose_name="父评论",to='Comment', on_delete=models.CASCADE ,null=True ,blank=True )

    class Meta:
        ordering = ['-created_at']

    def __str__(self):
        return f"{self.user}评论:{self.article}"